package com.knife.easyexcel.read.message;


import com.knife.easyexcel.read.data.ValidateElementResult;

import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;

/**
 * 默认的异常构造器，简单的key:value样式
 *
 * @author lth
 * @created 2025年07月18日 星期五 8:22
 */
public class DefaultImportListenerErrorMsgBuilder<T> implements ImportListenerErrorMsgBuilder<T> {

    @Override
    public String build(List<ValidateElementResult<T>> validateElementResults) {
        List<ValidateElementResult<T>> errorValidateElementResults = validateElementResults.stream().filter(item -> !item.getFlag()).collect(Collectors.toList());
        StringJoiner stringJoiner = new StringJoiner("\n");
        errorValidateElementResults.forEach(item -> {
            String msg = item.getUniqueFieldValueName() + "：" + item.getResultMsg();
            stringJoiner.add(msg);
        });
        return stringJoiner.toString();
    }
}
